// pages/todayStop/todayStop.js
let app = getApp()
let util = require("../../utils/util")
let request = require("../../utils/request")


Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageAllHeight: app.globalData.pageAllHeight,
    nowDate: '',
    currentPage: 1,
    pageSize: 15,
    pageFlag: false,
    stopCarList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let date = util.formatTime(new Date())
    this.setData({
      nowDate: date
    })
    this.getParkOrderInfo()
  },
  /**
   * 获取停车场订单信息
   */
  getParkOrderInfo(next) {
    let that = this
    let nowDate = that.data.nowDate
    let parmas = {
      page: that.data.currentPage,
      size: that.data.pageSize,
      parkId: wx.getStorageSync('parkInfo').parkId
    }
    request.http('/order/orderInfo/getTodayParkingList', 'GET', parmas)
      .then(res => {
        let data = res.data
        console.log(data);
        let stopCarList = that.data.stopCarList
        let pageFlag = that.data.pageFlag
        if (data.code == 200) {
          if (next) {
            if (data.data.records.length > 0) {
              stopCarList = stopCarList.concat(data.data.records)
              pageFlag = false
            } else {
              pageFlag = true
            }
          } else {
            stopCarList = data.data.records
          }
          that.setData({
            stopCarList,
            pageFlag
          })
        }
      })
  },
  /**
  * 触底事件
  */
  scrollTolower() {
    if (this.data.pageFlag) {
      return
    }
    this.setData({
      pageFlag: true,
      currentPage: this.data.currentPage + 1
    })
    this.getParkOrderInfo(true)
  }
})